<?php

//echo '<html><head><title>Download Page</title></head><body>';

// Zip it up!

$fileList = array();
$dirToZip = 'qrOutput';

createZipArchive($dirToZip);

function createZipArchive ($dirToZip) {
$qrCodeZip = 'qrCodes.zip';
//echo 'this is a test!';
// prepare the zip archive
//create the zip object
  $zip = new ZipArchive();
  //create the file and throw the error if unsuccessful
  if ($zip->open($qrCodeZip, ZIPARCHIVE::CREATE )!==TRUE) {
    exit("cannot create <$qrCodeZip>\n");
  }


if ($handle = opendir($dirToZip)) {
		while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
             //$array_push($fileList,$file);
             $zip->addFile($dirToZip.'/'.$file) or die ("ERROR: Could not add file: $f");
             
            echo '<br>'.$dirToZip.'/'.$file;
        }        
              }
    
    closedir($handle);
    $zip->close();
    echo "<br>Archive created successfully."; 
}



  //then send the headers to force download the zip file
  header("Content-type: application/zip");
  header("Content-Disposition: attachment; filename=$qrCodeZip");
  header("Pragma: no-cache");
  header("Expires: 0");
  readfile("$qrCodeZip");
  exit;
  
}// end of createZipArchive

//echo '</body></html>';
?>
